<?php
/**
 * @package     Celtawebtickets component
 * @copyright   Copyright (C) 2012 CMExt Team http://www.cmext.vn/
 * @license     http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
 */

// No direct access
defined('_JEXEC') or die;

jimport('joomla.application.component.view');

class CeltawebticketsViewMailTemplate extends JView
{
	protected $form;
	protected $item;
	protected $state;

	public function display($tpl = null)
	{
		// Initialiase variables.
		$this->form		= $this->get('Form');
		$this->item		= $this->get('Item');
		$this->state	= $this->get('State');
        
		// Check for errors.
		if (count($errors = $this->get('Errors')))
        {
			JError::raiseError(500, implode("\n", $errors));
			return false;
		}
        
		$this->addToolbar();
		parent::display($tpl);
	}

	protected function addToolbar()
        {
                
			JRequest::setVar('hidemainmenu', true);

		$user		= JFactory::getUser();
		$isNew		= ($this->item->id == 0);
		$checkedOut	= !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id'));
		$canDo		= CeltawebticketsHelper::getActions();

		JToolBarHelper::title($isNew ? JText::_('COM_CELTAWEBTICKETS_MANAGER_MAIL_NEW') : JText::_('COM_CELTAWEBTICKETS_MANAGER_MAIL_EDIT'), 'celtawebtickets-mail');

		// If not checked out, can save the item.
		if (!$checkedOut && ($canDo->get('core.edit')||$canDo->get('core.create'))) {
			JToolBarHelper::apply('mailtemplate.apply');
			JToolBarHelper::save('mailtemplate.save');
		}
		if (!$checkedOut && $canDo->get('core.create')) {

			JToolBarHelper::save2new('mailtemplate.save2new');
		}
		// If an existing item, can save to a copy.
		if (!$isNew && $canDo->get('core.create')) {
			JToolBarHelper::save2copy('mailtemplate.save2copy');
		}

		if (empty($this->item->id))  {
			JToolBarHelper::cancel('mailtemplate.cancel');
		} else {
			JToolBarHelper::cancel('mailtemplate.cancel', 'JTOOLBAR_CLOSE');
		}

		JToolBarHelper::divider();
		JToolBarHelper::help('JHELP_COMPONENTS_CELTAWEBTICKETS_USERS_EDIT');
    }
}
